<?php 
/**
 * Description of form
 * @author diotheos
 * @since 7 мая 2010
 */
class App_Form_User_RestorePassword extends Lib_Form_Clear{
	/**
	 * Initialization of form function
	 * 
	 * @since 7 мая 2010
	 * @author diotheos
	 * @return Zend_Form
	 */
	public function init(){
		parent::init();
		$this->setMethod('post');
        $this->setAction('');
		$email = new Zend_Form_Element_Text('email');
        
        $email->setRequired()
              ->setLabel(_('Мой Email'))
              ->setFilters(array(
                    'StringToLower',
                    'StringTrim'
              ))
              ->addValidators(array(
                    array('NotEmpty', true),
                    array('stringLength', false, array(6,40)),
                    new Zend_Validate_EmailAddress(
                        Zend_Validate_Hostname::ALLOW_DNS,
                        true
                    ),
                    new Lib_Form_Validate_DbHasRecord('User','email')
              ));
        $this->addElement($email);
        
        $imgDir = dirname(APPLICATION_PATH) . "/public/img/captcha/";
               
       // check captcha path is writeable        
        if (is_writable($imgDir)) {
            $captcha = new Zend_Form_Element_Captcha('captcha', array(
                    'label' => _('Введите цифры с изображения'),
                    'captcha' => 'Image',
                    'captchaOptions' => array(
                        'captcha' => 'Image',
                        'wordLen' => 4,
                        'timeout' => 300,
                        'imgDir' => $imgDir,
                        'imgUrl' => 'img/captcha/',
                        'suffix' => '.c.png',
                        'font' => dirname(APPLICATION_PATH) . 
                                  "/assets/fonts/Aksent_Normal.ttf",
                    ),
                ));

        } else {
            $captcha = new Zend_Form_Element_Captcha('captcha', array(
                    'label' => "Введите цифры с изображения",
                    'captcha' => 'Figlet',
                    'captchaOptions' => array(
                        'wordLen' => 6,
                        'timeout' => 300,
                    ),
                ));
        }
        $this->addElement($captcha);
        
        $submit = new Zend_Form_Element_Submit('restore');
        $submit->setLabel(_('Восстановить'));
//        $submit->setLabel();
        $this->addElement($submit);
        $this->setDecorators(array(
            array('ViewScript', array('viewScript'=>'user/forms/restore-password.phtml', 'class'=> 'form element'))
        ));
		return $this;
	}
}